package com.xuzz.study.spring.simpleioc.utils;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.NoOp;

import java.lang.reflect.Constructor;

public class BeanUtils {
    public static <T> T instanceByCglib(Class<T> clazz, Constructor ctr,Object[] args)
    {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(clazz);
        enhancer.setCallback(NoOp.INSTANCE);

        if(null==ctr)
        {
            return (T)enhancer.create();
        }
        else
        {
            return (T)enhancer.create(ctr.getParameterTypes(),args);
        }
    }
}
